/**
 * Created by Administrator on 2017/7/14 0014.
 */
$(function($) {
    var zoomLevel = 12;
    var zoomLevel2 = 16;
    var map = new BMap.Map("myMap",{enableMapClick:false});
    var countryMap = new BMap.Map("countryMap",{enableMapClick:false});
    window.map = map;
    map.enableDragging();
    map.disable3DBuilding();
    map.disableDoubleClickZoom();
    map.setMapStyle({style:'midnight'});
    map.centerAndZoom(new BMap.Point(118.216664,37.139767),zoomLevel);

    /* 各村地图 */
    var myStyleJson = [
        {
            "featureType": "water",
            "elementType": "all",
            "stylers": {
                "color": "#021019"
            }
        },
        {
            "featureType": "highway",
            "elementType": "geometry.fill",
            "stylers": {
                "color": "#000000"
            }
        },
        {
            "featureType": "highway",
            "elementType": "geometry.stroke",
            "stylers": {
                "color": "#147a92"
            }
        },
        {
            "featureType": "arterial",
            "elementType": "geometry.fill",
            "stylers": {
                "color": "#000000"
            }
        },
        {
            "featureType": "arterial",
            "elementType": "geometry.stroke",
            "stylers": {
                "color": "#0b3d51"
            }
        },
        {
            "featureType": "local",
            "elementType": "geometry",
            "stylers": {
                "color": "#000000"
            }
        },
        {
            "featureType": "land",
            "elementType": "all",
            "stylers": {
                "color": "#08304b"
            }
        },
        {
            "featureType": "railway",
            "elementType": "geometry.fill",
            "stylers": {
                "color": "#000000"
            }
        },
        {
            "featureType": "railway",
            "elementType": "geometry.stroke",
            "stylers": {
                "color": "#08304b"
            }
        },
        {
            "featureType": "subway",
            "elementType": "geometry",
            "stylers": {
                "lightness": -70
            }
        },
        {
            "featureType": "building",
            "elementType": "geometry.fill",
            "stylers": {
                "color": "#000000"
            }
        },
        {
            "featureType": "all",
            "elementType": "labels.text.fill",
            "stylers": {
                "color": "#857f7f"
            }
        },
        {
            "featureType": "all",
            "elementType": "labels.text.stroke",
            "stylers": {
                "color": "#000000"
            }
        },
        {
            "featureType": "building",
            "elementType": "geometry",
            "stylers": {
                "color": "#022338"
            }
        },
        {
            "featureType": "green",
            "elementType": "geometry",
            "stylers": {
                "color": "#062032"
            }
        },
        {
            "featureType": "boundary",
            "elementType": "all",
            "stylers": {
                "color": "#1e1c1c"
            }
        },
        {
            "featureType": "background",
            "elementType": "all",
            "stylers": {
                "color": "#01264b"
            }
        }
    ];
    countryMap.enableDragging();
    countryMap.disable3DBuilding();
    countryMap.disableDoubleClickZoom();
    countryMap.setMapStyle({styleJson: myStyleJson });
    countryMap.centerAndZoom(new BMap.Point(118.216664,37.139767),zoomLevel2);

    //隐藏百度地图的版权信息
    setTimeout(function(){
        $(".anchorBL").hide();
    },1000);
    /* 添加行政区划 */
    function getBoundary(){
        var bdary = new BMap.Boundary();
        bdary.get("博兴县", function(rs){       //获取行政区域
            var count = rs.boundaries.length; //行政区域的点有多少个
            if (count === 0) {
                alert('未能获取当前输入行政区域');
                return ;
            }
            var pointArray = [];
            for (var i = 0; i < count; i++) {
                var ply = new BMap.Polygon(rs.boundaries[i], {strokeWeight: 3, strokeColor: "#fff",fillColor:'rgba(255,255,255,0.1)'}); //建立多边形覆盖物
                map.addOverlay(ply);  //添加覆盖物
                pointArray = pointArray.concat(ply.getPath());
            }
            // map.setViewport(pointArray);    //调整视野
            map.centerAndZoom(new BMap.Point(118.216664,37.139767),zoomLevel);
        });
    }
    setTimeout(function(){
        getBoundary();
    }, 2000);

    /* 中间地图打点 */
    var data = [
        [118.21640112835,37.35055303071],
        [118.20993725158,37.364364050583],
        [118.2115093473,37.364277536958],
        [118.21929990364,37.348332602219],
        [118.20055138191,37.362083754071],
        [118.19531424013,37.363091873182],
        [118.23155031147,37.354136687223],
        [118.23894082631,37.365540619517],
        [118.21929990364,37.348332602219],
        [118.17929082878,37.364717000171],
        [118.18513918482,37.361501242659],
        [118.18690897154,37.364529893094],
        [118.20378805931,37.355587256265],
        [118.20703649642,37.351560218886],
        [118.19576399744,37.335713676055],
        [118.18299814101,37.344493609877],
        [118.17788762437,37.344520531075],
        [118.19293259507,37.349215201414],
        [118.1743167926,37.341503422251],
        [118.24887317025,37.321655545699],
        [118.25833281684,37.326868333315],
        [118.23581359396,37.333885195368],
        [118.24747999093,37.335701161045],
        [118.22694140144,37.343384251658],
        [118.21336838786,37.32933217991],
        [118.21313627111,37.313697903843],
        [118.2047234828,37.321291650479],
        [118.28166701841,37.349605707746],
        [118.27891744269,37.348961991882],
        [118.26543045174,37.351561782588],
        [118.25765518547,37.343428372208],
        [118.28828562292,37.360346766642],
        [118.2993994003,37.345718811858],
        [118.27668193038,37.34319812736],
        [118.14164862096,37.315614379551],
        [118.14873211743,37.316124866268],
        [118.16396734026,37.351448294589],
        [118.16393681763,37.349127646967],
        [118.15688634107,37.336458857942],
        [118.17739127015,37.322535579412],
        [118.18130753274,37.309814504364],
        [118.15517650816,37.309526268059],
        [118.13592736797,37.303313718354],
        [118.13856415694,37.289160688685],
        [118.1154188286,37.331251627781],
        [118.11484229253,37.327991162376],
        [118.13378067651,37.340016577393],
        [118.13071485323,37.335554019532],
        [118.12901405637,37.332077080076],
        [118.12526540861,37.332055835369],
        [118.10692306022,37.332971619953],
        [118.12021760717,37.321950506018],
        [118.12270221242,37.322536424487],
        [118.12575045227,37.324415351124],
        [118.13228035449,37.350536435974],
        [118.12605217333,37.352717164184],
        [118.15273958048,37.340377772578],
        [118.14674966228,37.348201135016],
        [118.1381183917,37.347345564465],
        [118.12836387273,37.356421026485],
        [118.13143753552,37.357737499427],
        [118.13936290954,37.352886838858],
        [118.14386975051,37.358485220423],
        [118.15193613693,37.360834959752],
        [118.16363812836,37.362713257556],
        [118.26135635868,37.351234491702],
        [118.12723298783,37.221346648419],
        [118.12544569943,37.224196000038],
        [118.12025290789,37.218044938371],
        [118.12746375264,37.250882916038],
        [118.11986413653,37.24905314621],
        [118.12342547412,37.246600321306],
        [118.13363518875,37.241309964683],
        [118.13466963515,37.235348616826],
        [118.14133650651,37.235505077384],
        [118.14415977293,37.237214500915],
        [118.14713045847,37.232501590799],
        [118.15045837586,37.233308598498],
        [118.15866872653,37.231379711965],
        [118.16562945877,37.233063626425],
        [118.16310023829,37.242985482653],
        [118.15406150352,37.241597801345],
        [118.14470807077,37.244822670895],
        [118.12976158669,37.236872144303],
        [118.13850502868,37.251061209639],
        [118.14699277249,37.264625935042],
        [118.15900998111,37.264698174777],
        [118.10738655981,37.228797702434],
        [118.10674459746,37.237618591759],
        [118.10618126199,37.240777432435],
        [118.10392676399,37.249140627778],
        [118.09914862398,37.246383721303],
        [118.09552984964,37.236530698471],
        [118.09864647569,37.225379216642],
        [118.08948833007,37.215172261098],
        [118.09032069456,37.206286718386],
        [118.09798098043,37.209032048292],
        [118.10438204588,37.214411610078],
        [118.10848080103,37.212355649905],
        [118.12368470083,37.199648454198],
        [118.13873508202,37.208506115395],
        [118.13325009146,37.200246748096],
        [118.1492885126,37.21389150213],
        [118.1354509202,37.228629977605],
        [118.13350520304,37.232371646334],
        [118.12720754782,37.231328601933],
        [118.11913420132,37.23706787576],
        [118.12426820596,37.222125285175],
        [118.17451586698,37.271821277795],
        [118.1684330532,37.258725943439],
        [118.12976158669,37.236872144303],
        [118.11034626267,37.253735375445],
        [118.12976158669,37.236872144303],
        [118.12499081459,37.262819367073],
        [118.12976158669,37.236872144303],
        [118.12976158669,37.236872144303],
        [118.31381048082,37.278177016823],
        [118.16030267329,36.996958793779],
        [118.30146445195,37.272849733873],
        [118.29313293065,37.272845364032],
        [118.28811624742,37.267357900948],
        [118.28775337421,37.27225037674],
        [118.28103560845,37.271480295588],
        [118.28159969401,37.275406548947],
        [118.26279883611,37.266382002771],
        [118.33564753768,37.259706248169],
        [118.32846998592,37.254526333817],
        [118.33460848117,37.255685904218],
        [118.3451524463,37.261409309468],
        [118.35587023893,37.272259559021],
        [118.3517959671,37.273223723257],
        [118.33093727543,37.282180438329],
        [118.27625700492,37.314096245804],
        [118.28944167025,37.298725468935],
        [118.27500216644,37.297233094928],
        [118.31164211415,37.303328460938],
        [118.31776196236,37.30450389199],
        [118.31133211251,37.296523997486],
        [118.29404523985,37.296248558061],
        [118.30039828728,37.299336736168],
        [118.29548688096,37.297935414251],
        [118.30821681325,37.291069761351],
        [118.28090556615,37.261941482409],
        [118.28931013227,37.256741408947],
        [118.28919292406,37.256671609796],
        [118.30709238718,37.253871224279],
        [118.27859731715,37.244928123139],
        [118.26817459991,37.251010513998],
        [118.28256768018,37.166477366161],
        [118.27651994254,37.166206853554],
        [118.28746321255,37.168702120567],
        [118.28024983547,37.161817857076],
        [118.28244215815,37.166454807605],
        [118.25121024318,37.142734968195],
        [118.31570286827,37.160176738957],
        [118.31376336828,37.172154201959],
        [118.3212561552,37.165987087107],
        [118.31574660766,37.179935328285],
        [118.32452042316,37.180747410559],
        [118.3760107057,37.189673401524],
        [118.3787049997,37.198292457597],
        [118.37644533824,37.181535274548],
        [118.36505751929,37.163428715695],
        [118.35652648254,37.190624893778],
        [118.34148033237,37.194426584333],
        [118.36248905094,37.200609307611],
        [118.35951117536,37.221429132005],
        [118.34321627184,37.213958900686],
        [118.31625544563,37.197663405453],
        [118.31960948934,37.210493999221],
        [118.32080662247,37.209850903583],
        [118.32044359206,37.206157758566],
        [118.3176815227,37.208019069212],
        [118.32136908299,37.213364821532],
        [118.30768587876,37.204066465246],
        [118.29396027452,37.201321278748],
        [118.28792557938,37.202734212454],
        [118.31819148804,37.190202265671],
        [118.27969103555,37.200373843948],
        [118.28931490317,37.209549962154],
        [118.29454550798,37.21001468351],
        [118.29295544794,37.210695493419],
        [118.29186529043,37.230099600859],
        [118.26828585055,37.222331116743],
        [118.26216572117,37.212957018605],
        [118.26842946176,37.204016271565],
        [118.22571531705,37.19135384581],
        [118.2695584108,37.229365021419],
        [118.26790977944,37.241031744832],
        [118.31789436182,37.044115585316],
        [118.33073280852,37.058879784371],
        [118.31743400629,37.065751351299],
        [118.30779013969,37.063993483015],
        [118.31279770873,37.050302928648],
        [118.30499323225,37.051857909769],
        [118.29314109535,37.05063208709],
        [118.29137262825,37.046710292668],
        [118.29494998621,37.053825421162],
        [118.2964624111,37.048684028164],
        [118.30172826811,37.073823051304],
        [118.276167584,37.080757192532],
        [118.33447375511,37.069238894674],
        [118.30308466542,37.07840833648],
        [118.30340006228,37.085725962308],
        [118.29961627999,37.080456301483],
        [118.30683935518,37.093295813919],
        [118.29908100759,37.092209823031],
        [118.3022838,37.093418485968],
        [118.30378140554,37.106150795108],
        [118.27272470596,37.117429058544],
        [118.29029820186,37.099439784198],
        [118.29351605436,37.111319881632],
        [118.29314869502,37.095440329214],
        [118.29462359768,37.099668637852],
        [118.30159514013,37.102678339972],
        [118.27450424289,37.099088859261],
        [118.33757578459,37.120212006175],
        [118.32865824381,37.113018349845],
        [118.33988754058,37.13278426474],
        [118.33561011966,37.113020522816],
        [118.33283276833,37.109430658013],
        [118.32082408553,37.097643186841],
        [118.35567803748,37.153442735984],
        [118.3021352607,37.123358975097],
        [118.30649122676,37.125063235815],
        [118.30983386737,37.12777381667],
        [118.30640462292,37.135569755614],
        [118.16471578954,37.097587168992],
        [118.1719267897,37.096678407932],
        [118.16615442133,37.092708274012],
        [118.20263588638,37.088426177586],
        [118.20263588638,37.088426177586],
        [118.20263588638,37.088426177586],
        [118.20263588638,37.088426177586],
        [118.16473580469,37.059928608949],
        [118.18051748741,37.057008767118],
        [118.18184132204,37.063363120983],
        [118.18366026134,37.059914935827],
        [118.1739682285,37.066087960764],
        [118.19370564805,37.100802864035],
        [118.21432284735,37.103169212488],
        [118.21718325062,37.10811521985],
        [118.21817806109,37.118235520285],
        [118.22759611524,37.091840314913],
        [118.24388044302,37.112663206715],
        [118.24445476387,37.096440521494],
        [118.25065653934,37.087522034135],
        [118.24731776863,37.084169992248],
        [118.23979071854,37.077356731006],
        [118.23526383818,37.076569747044],
        [118.22818140979,37.084228168067],
        [118.22322984023,37.086976245444],
        [118.19386755863,37.212322554676],
        [118.17724305873,37.24425897029],
        [118.18255195087,37.245406067129],
        [118.17950927692,37.245460903027],
        [118.20190761393,37.246879872021],
        [118.19239622583,37.236638960649],
        [118.1859039653,37.227043487193],
        [118.20106056304,37.229546354934],
        [118.20250958911,37.238413157313],
        [118.2214187054,37.243336597919],
        [118.21685242087,37.243098646077],
        [118.22049411188,37.232210640421],
        [118.21103653857,37.223508904635],
        [118.21398864805,37.229740008753],
        [118.22359697409,37.226306193183],
        [118.22504095888,37.221593792789],
        [118.24633362823,37.234182460644],
        [118.24809966902,37.298477154754],
        [118.22740106796,37.289705801791],
        [118.25438229199,37.273392818858],
        [118.2493712546,37.274306884923],
        [118.23866191772,37.266599918714],
        [118.2412411828,37.261984601639],
        [118.23506696105,37.260628173873],
        [118.25222482805,37.262531870156],
        [118.25036093036,37.244351204811],
        [118.2306668828,37.265796124423],
        [118.21073688092,37.260477279746],
        [118.19434641835,37.259548124876],
        [118.18335760964,37.258887333613],
        [118.1826743962,37.27645029822],
        [118.1813555804,37.285164870682],
        [118.17597410877,37.298714545249],
        [118.19554271875,37.269397766408],
        [118.19830397783,37.282138848474],
        [118.20829963255,37.295936748961],
        [118.21759915259,37.303629669167],
        [118.21381959684,37.305552693049],
        [118.21402794802,37.295180514916],
        [118.21147306115,37.295156009414],
        [118.21313806772,37.27355044784],
        [118.26414577875,37.025729262482],
        [118.26414577875,37.025729262482],
        [118.26414577875,37.025729262482],
        [118.26414577875,37.025729262482],
        [118.2444210307,37.029386608005],
        [118.25642818728,37.023175096858],
        [118.26390258499,37.022989564838],
        [118.27448367978,37.023725521078],
        [118.27831240967,37.02409036983],
        [118.26414577875,37.025729262482],
        [118.26452180314,37.051711399709],
        [118.26456336954,37.046911807867],
        [118.27012047157,37.05219531549],
        [118.27383028109,37.039886281215],
        [118.24039410316,37.050702439597],
        [118.26414577875,37.025729262482],
        [118.23469081897,37.059117051158],
        [118.26414577875,37.025729262482],
        [118.24907874387,37.056757586348],
        [118.23623989293,37.052208538911],
        [118.23198433766,37.047515012962],
        [118.23369111813,37.036370189596],
        [118.29199685985,37.035503866255],
        [118.28658095077,37.042148657763],
        [118.28724795699,37.029882643744],
        [118.26414577875,37.025729262482],
        [118.29678142633,37.033053175362],
        [118.30100454019,37.035800600298],
        [118.3094528484,37.033511501913],
        [118.30642050855,37.030265800967],
        [118.30899880976,37.029486009249],
        [118.26414577875,37.025729262482],
        [118.2292273599,37.01737383953],
        [118.24296106326,37.00940765156],
        [118.23930512333,36.996254646397],
        [118.22759590414,36.984423675207],
        [118.18393423374,37.02182169627],
        [118.18393423374,37.02182169627],
        [118.18393423374,37.02182169627],
        [118.15360977352,37.029597887684],
        [118.14957560744,37.029808497944],
        [118.18530083849,37.025678562549],
        [118.1855014876,37.023992402655],
        [118.18485788135,37.020922511973],
        [118.18920931187,37.017802282083],
        [118.18864444838,37.014914664091],
        [118.20101541959,37.049285076857],
        [118.2286785626,37.06397463358],
        [118.2235724234,37.061555068268],
        [118.22503862867,37.058113032666],
        [118.2297026219,37.053966584912],
        [118.22931116282,37.050643561418],
        [118.17127920216,36.998049295935],
        [118.17209467671,36.994814050927],
        [118.15567107116,37.01229848923],
        [118.17556469795,37.016405188931],
        [118.18393423374,37.02182169627],
        [118.18126161226,36.997403527151],
        [118.18996692656,36.995896456727],
        [118.19964028004,37.010026980485],
        [118.18393423374,37.02182169627],
        [118.18393423374,37.02182169627],
        [118.21169874065,37.020722723726],
        [118.20890894599,36.998447451028],
        [118.19961473583,36.992668143165],
        [118.20816525413,36.984837956669],
        [118.18393423374,37.02182169627],
        [118.18393423374,37.02182169627],
        [118.22571531705,37.19135384581],
        [118.09943299067,37.164028984281],
        [118.09943299067,37.164028984281],
        [118.13216343015,37.153749308388],
        [118.09943299067,37.164028984281],
        [118.09943299067,37.164028984281],
        [118.08454828487,37.147162290621],
        [118.22571531705,37.19135384581],
        [118.0812193461,37.160977165029],
        [118.09633280451,37.157434012874],
        [118.10316887621,37.156593400433],
        [118.10046794103,37.156179512222],
        [118.08907196636,37.183875125434],
        [118.09290675084,37.182217987921],
        [118.10319105447,37.183350483996],
        [118.10737337359,37.194929528138],
        [118.12067586875,37.181427446471],
        [118.11786917337,37.173188435472],
        [118.10659732476,37.16911876885],
        [118.10868330873,37.159966009402],
        [118.13048313263,37.130648521424],
        [118.13048313263,37.130648521424],
        [118.13048313263,37.130648521424],
        [118.13048313263,37.130648521424],
        [118.13623539064,37.138544704783],
        [118.13048313263,37.130648521424],
        [118.13048313263,37.130648521424],
        [118.13048313263,37.130648521424],
        [118.13048313263,37.130648521424],
        [118.08719735727,37.137366604984],
        [118.08787456015,37.140634904237],
        [118.10964146834,37.135047264085],
        [118.09846611212,37.140107929644],
        [118.10618692491,37.142212501263],
        [118.1083559159,37.13340963396],
        [118.11225834368,37.132021814227],
        [118.13313261915,37.122675721328],
        [118.07243456949,37.107918601913],
        [118.07749828261,37.108931779311],
        [118.08221165659,37.109772057696],
        [118.08461756668,37.111218409734],
        [118.08870784182,37.111057397281],
        [118.09173176094,37.113016455663],
        [118.09634221067,37.113343419278],
        [118.10177149012,37.113182020431],
        [118.10915812697,37.111868611919],
        [118.11743411233,37.112768983118],
        [118.12482550212,37.112847347564],
        [118.13471925395,37.11254796351],
        [118.14107851496,37.112411087589],
        [118.14864892536,37.109943231096],
        [118.15793981539,37.107951563401],
        [118.15669322785,37.093016063696],
        [118.15125226503,37.089977266045],
        [118.13048313263,37.130648521424],
        [118.18330140266,37.159000406897],
        [118.18330140266,37.159000406897],
        [118.1702667858,37.174980014101],
        [118.17875760002,37.175236366801],
        [118.18724109216,37.175354248028],
        [118.19503857442,37.175017744596],
        [118.20514964073,37.176707830522],
        [118.20319176052,37.170823891906],
        [118.13434097122,37.180589975036],
        [118.15464192925,37.195283427684],
        [118.14814334285,37.16855110487],
        [118.1543542496,37.169658736326],
        [118.16052568392,37.167470594615],
        [118.17202089709,37.163302641338],
        [118.17580294115,37.157823664433],
        [118.22571531705,37.19135384581],
        [118.16640637806,37.156417307933],
        [118.16373799478,37.157915922784],
        [118.1582796767,37.158076337417],
        [118.15599662516,37.15813402593],
        [118.15637245553,37.140302548625],
        [118.15709247883,37.138019982759],
        [118.15369125971,37.138031923321],
        [118.20903049301,37.176735131946],
        [118.1997763365,37.179957681659],
        [118.20470096228,37.182997556333],
        [118.20827394101,37.188968071525],
        [118.20257811545,37.19266360969],
        [118.19962709202,37.197789961752],
        [118.20835175134,37.198890393893],
        [118.20153894396,37.203282214428],
        [118.21074739828,37.202404141636],
        [118.20565225255,37.210165481088],
        [118.209477665,37.214442436206],
        [118.22984072829,37.215173364316],
        [118.2411550883,37.214567617911],
        [118.24571324138,37.218550152068],
        [118.24895991602,37.219449726339],
        [118.25168158768,37.219101808776]
    ];
    var data4 = [
        [118.136748,37.172685],
        [118.137428,37.144482],
        [118.132756,37.160301],
        [118.255758,37.052953],
        [118.161472,37.049266],
        [118.222118,37.245915],
        [118.203959,37.106518],
        [118.306582,37.073355],
        [118.104204,37.224339],
        [118.280171,37.213496],
        [118.285202,37.267048],
        [118.218817,37.349822]
    ]
    //普通标注点方法
    var drawPoints = function(data,color,size){
        var points = [];
        for (var i = 0; i < data.length; i++) {
            points.push(new BMap.Point(data[i][0], data[i][1]));
        }
        var options = {
            size: size,
            shape: BMAP_POINT_SHAPE_CIRCLE,
            color: color
        }
        var pointCollection = new BMap.PointCollection(points, options);
        map.addOverlay(pointCollection);  // 添加Overlay
        pointCollection.addEventListener('click', countryMapEvent);
    }
    drawPoints(data,'rgba(9,212,255,1)', (300,300));
    drawPoints(data4,'rgba(255,210,0,1)',BMAP_POINT_SIZE_BIG);
    //点击大地图将经纬度传给小地图
    function countryMapEvent(e) {
        var arr1 = [];var arr2 = [];
        for(var item in e){
            arr1.push(e[item]);
        }

        for(var item in arr1[4]){
            arr2.push(arr1[4][item]);
        }

        var p_str = arr2[0] + "," + arr2[1];

        //console.log(p_str);
        var p_html = '<span class="countryName">博兴县乔庄镇陈家荒村</span>';
            p_html += '<div class="countryNum">';
            p_html += '<li><p><span>11</span>户</p><i>党员户</i></li>';
            p_html += '<li><p><span>111</span>户</p><i>贫困户</i></li>';
            p_html += '<li><p><span>111</span>人</p><i>贫困人口</i></li>';
            p_html += '</div>';
        $('.countryMsg').html(p_html);

        $('.mapRight').animate({right:'0.104vw'});
        $('.ifShowMap').fadeIn();
        $('.ifShowMap').attr('data-flag','show').text('>');
        countryMap.centerAndZoom(new BMap.Point(e.point.lng,e.point.lat),zoomLevel2);
        countryMap.clearOverlays();
        // 随机向地图添加10个标注
        var bounds = countryMap.getBounds();
        var sw = bounds.getSouthWest();
        var ne = bounds.getNorthEast();
        var lngSpan = Math.abs(sw.lng - ne.lng);
        var latSpan = Math.abs(ne.lat - sw.lat);
        var countryPoints = [];
        var countryPoints2 = [];
        var countryPoints3 = [];
        var countryPoints4 = [];
        var countryPoints5 = [];
        for (var i = 0; i < 3; i ++) {
            countryPoints.push(new BMap.Point(sw.lng + lngSpan * (Math.random() * 0.8), ne.lat - latSpan * (Math.random() * 0.8)));
        }
        for (var i = 0; i < 2; i ++) {
            countryPoints2.push(new BMap.Point(sw.lng + lngSpan * (Math.random() * 0.8), ne.lat - latSpan * (Math.random() * 0.8)));
        }
        for (var i = 0; i < 2; i ++) {
            countryPoints3.push(new BMap.Point(sw.lng + lngSpan * (Math.random() * 0.8), ne.lat - latSpan * (Math.random() * 0.8)));
        }
        for (var i = 0; i < 2; i ++) {
            countryPoints4.push(new BMap.Point(sw.lng + lngSpan * (Math.random() * 0.8), ne.lat - latSpan * (Math.random() * 0.8)));
        }
        countryPoints5.push(new BMap.Point(sw.lng + lngSpan * (Math.random() * 0.8), ne.lat - latSpan * (Math.random() * 0.8)));
        var options = {
            size:  BMAP_POINT_SIZE_BIG,
            shape: BMAP_POINT_SHAPE_CIRCLE,
            color: '#09d4ff'
        }
        var options2 = {
            size:  BMAP_POINT_SIZE_BIG,
            shape: BMAP_POINT_SHAPE_CIRCLE,
            color: '#7cf102'
        }
        var options3 = {
            size:  BMAP_POINT_SIZE_BIG,
            shape: BMAP_POINT_SHAPE_CIRCLE,
            color: '#ffd200'
        }
        var options4 = {
            size: BMAP_POINT_SIZE_BIG,
            shape: BMAP_POINT_SHAPE_CIRCLE,
            color: '#ff787a'
        }
        var options5 = {
            size:  BMAP_POINT_SIZE_BIG,
            shape: BMAP_POINT_SHAPE_CIRCLE,
            color: '#fefeff'
        }
        var countryPointCollection = new BMap.PointCollection(countryPoints, options);  // 初始化PointCollection       低保贫困户
        var countryPointCollection2 = new BMap.PointCollection(countryPoints2, options2);  // 初始化PointCollection     五保贫困户
        var countryPointCollection3 = new BMap.PointCollection(countryPoints3, options3);  // 初始化PointCollection     一般贫困户
        var countryPointCollection4 = new BMap.PointCollection(countryPoints4, options4);  // 初始化PointCollection     党员户
        var countryPointCollection5 = new BMap.PointCollection(countryPoints5, options5);  // 初始化PointCollection     已脱贫
        countryMap.addOverlay(countryPointCollection);
        countryMap.addOverlay(countryPointCollection2);
        countryMap.addOverlay(countryPointCollection3);
        countryMap.addOverlay(countryPointCollection4);
        countryMap.addOverlay(countryPointCollection5);
        countryPointCollection.addEventListener('click', rightHouseMsg);
        countryPointCollection2.addEventListener('click', rightHouseMsg);
        countryPointCollection3.addEventListener('click', rightHouseMsg);
        countryPointCollection4.addEventListener('click', rightHouseMsg);
        countryPointCollection5.addEventListener('click', rightHouseMsg);
        // var drawPoint = function(data,color){
        //     var points2 = [];
        //     for (var t = 0; t < data.length; t++) {
        //         points2.push(new BMap.Point(data[t][0], data[t][1]));
        //     }
        //     // points2.push(new BMap.Point(e.point.lng, e.point.lat));
        //     var options2 = {
        //         size: BMAP_POINT_SIZE_SMALL,
        //         shape: BMAP_POINT_SHAPE_CIRCLE,
        //         color: color
        //     }
        //     var countryPointCollection = new BMap.PointCollection(points2, options2);
        //     countryMap.addOverlay(countryPointCollection);  // 添加Overlay
        // }
        // drawPoint(data1,'rgba(124,241,2,1)');
        // drawPoint(data2,'rgba(180,66,255,1)');
        // drawPoint(data3,'rgba(255,210,0,1)');
    }

    /* 贫困户信息切换 */
    var swiperMsg = new Swiper('.swiper-msg', {
        pagination: '.swiperMsgPage',
        paginationClickable: true,
        autoplay: 6 * 1000,
        autoplayDisableOnInteraction: false,
        observer:true,
        observeParents:true,
    });
    $('.swiper-msg').mouseenter(function(){
        swiperMsg.stopAutoplay();
    }).mouseleave(function(){
        swiperMsg.startAutoplay();
    })
    var imgs = ['1.jpg','2.jpg','3.jpg','4.jpg'];
    var leaderImgs = ['leader01.jpg','leader02.jpg','leader03.jpg','leader04.jpg'];
    var current = 0;
    function rightHouseMsg(e){
        swiperMsg.slideTo(0, 200, false);

        /* 领导和贫困户照片随机切换 */
        $('.familyImg .swiper-slide img').attr('src','images/'+ imgs[current]);
        $('.leaderPhoto img').attr('src','images/'+ leaderImgs[current]);
        current++;
        if(current > 3) current =0;

    }

    /* 各贫困村名字轮播 */
    var timer = 2000;
    var itemIndex = 0;
    setTimeout(function(){
        setInterval(function(){
            for(var i = 0; i < 32; i++){
                if(itemIndex == i){
                    infos[i][0].show();
                    infos[i][1].show();
                }else{
                    infos[i][0].hide();
                    infos[i][1].hide();
                }
            }
            itemIndex++;
            if(itemIndex > 31) itemIndex = 0;
        }, timer);
    }, timer * 5);
    // 弹出层覆盖物
    function ComplexCustomOverlay(point,title){
        this._point = point;
        this._title = title;
    }
    ComplexCustomOverlay.prototype = new BMap.Overlay();
    ComplexCustomOverlay.prototype.initialize = function(map){
        this._map = map;
        var div = this._div = document.createElement("div");
        $(div).addClass('tip');
        div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);
        $(div).append('<div class="tip">' +
            '<h2>'+this._title+'</h2>' +
            '</div>');
        map.getPanes().labelPane.appendChild(div);
        return div;
    }
    ComplexCustomOverlay.prototype.draw = function(){
        var map = this._map;
        var pixel = map.pointToOverlayPixel(this._point);
        this._div.style.left = pixel.x - 90 + "px";
        this._div.style.top  = pixel.y - 30 + "px";
    }
    // 水滴覆盖物
    function WaterDropOverlay(point){
        this._point = point;
    }
    WaterDropOverlay.prototype = new BMap.Overlay();
    WaterDropOverlay.prototype.initialize = function(map){
        this._map = map;
        var div = this._div = document.createElement("div");
        $(div).addClass('water');
        div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);
        $(div).append('<img src="images/yellowPos.png"/>');
        map.getPanes().labelPane.appendChild(div);
        return div;
    }
    WaterDropOverlay.prototype.draw = function(){
        var map = this._map;
        var pixel = map.pointToOverlayPixel(this._point);
        this._div.style.left = pixel.x - 13 + "px";
        this._div.style.top  = pixel.y - 42 + "px";
    }
    var flag = 0;
    var myCompOverlay = '';
    var waterDropOverlay = '';
    //弹出层移动的点
    var waterdata = [
        [108.866586,34.105817,'***村'],
        [108.871764,33.998126,'***村'],
        [108.784681,34.204685,'***村'],
        [109.129619,34.031432,'***村'],
        [109.121756,33.999678,'***村'],
        [108.921327,34.044031,'***村'],
        [108.939481,34.040237,'***村'],
        [109.02832,34.016997,'***村'],
        [109.010141,34.009491,'***村'],
        [109.057476,34.176161,'***村'],
        [109.069527,34.170482,'***村'],
        [109.071898,34.168092,'***村'],
        [109.069141,34.165267,'***村'],
        [109.06073,34.184507,'***村'],
        [109.079202,34.15976,'***村'],
        [114.592622,38.076875,'***村'],
        [108.990415,34.071838,'***村'],
        [108.982041,34.052648,'***村'],
        [109.159081,34.135173,'***村'],
        [109.137729,34.107532,'***村'],
        [109.048442,34.026095,'***村'],
        [109.145988,34.006208,'***村'],
        [109.157568,34.016785,'***村'],
        [109.193855,33.922645,'***村'],
        [109.187452,33.987404,'***村'],
        [109.14476,34.027584,'***村'],
        [109.191469,33.937336,'***村'],
        [108.969811,33.971868,'***村'],
        [108.936559,33.955158,'***村'],
        [108.942341,33.940463,'***村'],
        [109.205707,34.113873,'***村'],
        [109.056946,34.135899,'***村']
    ];
    var waterPoints = [];
    var infos = [];
    for (var flag = 0; flag < waterdata.length; flag++) {
        //waterPoints.push();
        var wp = new BMap.Point(waterdata[flag][0], waterdata[flag][1]);
        myCompOverlay = new ComplexCustomOverlay(wp, waterdata[flag][2]);
        waterDropOverlay = new WaterDropOverlay(wp);
        map.addOverlay(myCompOverlay);
        map.addOverlay(waterDropOverlay);
        myCompOverlay.hide();
        waterDropOverlay.hide();
        infos.push([myCompOverlay, waterDropOverlay]);
    }
});